package com.ymatou.iapi.productmanager.testcase;

import org.json.JSONObject;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.productmanager.parameter.ProductCategoryListBean;
import com.ymatou.iapi.productmanager.service.GetProductCategoryListCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.tag.P1;
import com.ymttest.business.service.ProductManagerCallService;
import com.ymttest.utils.MapUtil;
import com.ymttest.utils.compare.AssertHelper;

public class Ts_GetProductCategoryList {
	private static GetProductCategoryListCall getProductCategoryListCall = new GetProductCategoryListCall();
	
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("获取全部商品类目列表");
	}
	
	@Before
	public void caseUp() {
	}
	
	@AfterClass
	public static void tearDown() {
		Logger.generateResult(getProductCategoryListCall.getOpurl());
	}
	
	@After
	public void caseDown() {
		Logger.end();
	}
	
	

	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetProductCategoryList_001() {
		Logger.start(true,"获取全部商品类目列表-查所有,根节点");
		try{
			checkGetProductCatalogList(-1);
		}catch(Exception e){
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetProductCategoryList_002() {
		Logger.start(true,"获取全部商品类目列表-查level1");
		try{
			checkGetProductCatalogList(0);
		}catch(Exception e){
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetProductCategoryList_003() {
		Logger.start(true,"获取全部商品类目列表-查level2");
		try{
			checkGetProductCatalogList(1051);
			
		}catch(Exception e){
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetProductCategoryList_004() {
		Logger.start(true,"获取全部商品类目列表-查level3");
		try{
			checkGetProductCatalogList(1081);
			
		}catch(Exception e){
			Logger.fail(e);
		}
	}

	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetProductCategoryList_005() {
		Logger.start(true,"获取全部商品类目列表-查不存在");
		try{
			JSONObject ret = getProductCategoryListCall.callAndGetReturnData(MapUtil.hashMap("parentId",123123123));
			Logger.verifyEquals(true, ret.getJSONObject("Data").isNull("categoryList"), "不存在id，所有返回应为null");
			
		}catch(Exception e){
			Logger.fail(e);
		}
	}

	
	
	
	public static void checkGetProductCatalogList(int parentId) throws Exception{
		
		JSONObject ret = getProductCategoryListCall.callAndGetReturnData(MapUtil.hashMap("parentId",parentId));
		
		ProductCategoryListBean actBean = ProductManagerCallService
										.getBeanFromJson(ret.getJSONObject("Data"),ProductCategoryListBean.class);
		
		ProductCategoryListBean tgtBean = ProductManagerCallService.getProductCategoryListBean(parentId);
		AssertHelper.assertResultEqual(tgtBean, actBean, "GetProductCategoryList");
		
	}
}
